#
# Web processing configuration module set up to 
# be run after the dataconf.py config module to
# serve the data created during that 
#
# All attributes may be written out as data but we use
# simple python functions to generate them.
#
import functools
from settings import *
from atlas import join_paths

#
# The title displayed on the index page.
#
TITLE = "<i>D. melanogaster</i> genome-wide nucleosome map"

# experiment name
expname  = 'fancydmel'

# the experiment directory, located in library/fancydmel
expdir = get_experiment_dir (expname)

# the database directory, located in library/fancydmel/db
dbdir = join_paths(expdir, 'db')

# setting up the databases
HDF_DATABASE = get_hdf_file( path=dbdir, name=expname )
SQL_URI      = get_sqlite_uri( path=dbdir, name=expname )

# Generate the chromosome dropdown menu. Must be a list of tuples
# where first element of the tuple is the key the second is the 
# visible text in the menu (kept the same in this case).
# 
# like so: [('chr01', 'chr01'), ('chr02', 'chr02'), ... ]
#
CHROM_FIELDS = get_chromosomes( fname=HDF_DATABASE, label='H2AZ')

# these are the valid zoom levels as integers
LEVELS = [ 50, 100, 250, 500, 1000, 2500, 5000, 10000, 20000, 50000, 100000, 200000 ]

# needs to be made into strings
LEVELS = map(str, LEVELS)

# this generates the zoom dropdown menu
# it must be a list of tuples where first element of the tuple is the key 
# the second is the 
# 
# like so: [('1000', '1,000'), ('10000', '10,000'), ... ]
#
ZOOM_LEVELS =  get_zoomlevels( LEVELS )

#
# Importing the main plotbuilder
#
from fancy_trackbuilder import build_tracks

# 
# customizes the build_track function with partial application 
# of certain parameters
#
twostrand_tracks = fill_params ( build_tracks, label='H2AZ', sigma=20, strand='twostrand' )
composite_tracks = fill_params ( build_tracks, label='H2AZ', sigma=20, strand='composite' )
pol2_tracks = fill_params ( build_tracks, label='POL2', sigma=20, strand='composite' )
bulk_tracks = fill_params ( build_tracks, label='BULK', sigma=20, strand='composite' )

#
# this is a helper datastructure that connects:
# an id, a visible dropdown menu entry, a page template and a plotting function
# 
#
PLOT_SETUP = [
    ('comp-id', 'H2AZ - composite' ,  'index.html', composite_tracks ),
    ('two-id' , 'H2AZ - two strand',  'index.html', twostrand_tracks ),
    ('pol2-id', 'POLII - nucleosomes',  'index.html', pol2_tracks ),
    ('all-id' , 'All nucleosomes',  'index.html', bulk_tracks ),
]

#
# no changes are needed below this line
#

#
# Generates the dropdown menu for the plot.
# The first element is the key the second the visible menu item. Like so:
#
# PLOT_CHOICES = [ ('composite-id', 'Composite'), ('twostrand-id', 'Two Stranded'), ]
#
#
# it is autogenerated it from the PLOT_SETUP
#
PLOT_CHOICES = [ (id, name) for (id, name, page, func) in PLOT_SETUP ]

#
# The plotmapper connects the plot id to a page template and a 
# plotting function
#
# it is autogenerated it from the PLOT_SETUP
#
PLOT_MAPPER = dict( [ (id, (page, func)) for (id, name, page, func) in PLOT_SETUP ] )
